package com.suncaper.shop.controller;

import com.suncaper.shop.domain.Comment;
import com.suncaper.shop.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
public class CommentController {


    @Autowired
    private CommentService commentService;

    @PostMapping("/comment")

    public String comment(@RequestParam("pid") Integer pid,
                          HttpSession session, Model model,
                          Comment c) {

        if (!commentService.saveComment(pid, c, session)) {
            model.addAttribute("msg", "没有权限请先登陆");
            return "create_account";
        }
        return "redirect:/simpleproduct/" + pid;

    }
}
